﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ProductRegPndQue.aspx.cs"
    Inherits="sWarranty.WEB.ProductRegPndQue" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../CSS/Table.css" />
    <link rel="stylesheet" type="text/css" href="../CSS/Menu.css" />
    <link href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" rel="stylesheet"
        type="text/css" />
    <script src="../JS/jquery-1.8.2.js" type="text/javascript"></script>
    <script src="../JS/jquery-ui.js" type="text/javascript"></script>
    <script src="../JS/jquery.dataTables.js" type="text/javascript"></script>
    <script src="../JS/notify.js" type="text/javascript"></script>
    <link href="../CSS/notify.css" rel="stylesheet" type="text/css" />
    <script src="../JS/jquery.simplemodal.js" type="text/javascript"></script>
    <link href="../JS/basic/css/basic_ie.css" rel="stylesheet" type="text/css" />
    <link href="../JS/basic/css/basic.css" rel="stylesheet" type="text/css" />
    <link href="../JS/basic/css/demo.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        function FormatTable() {
            $('.datatablecss').dataTable({
                "sScrollY": "200px",
                "bPaginate": false,
                "bFilter": true,
                "bScrollCollapse": true
            });
            //new FixedColumns(oTable);
        };

        function setReject(sn, curUser) {
            var xxx = "Serial No: " + sn + "\nUser Reject: " + curUser + "\n\nAre you sure reject this data...?";
            if (confirm(xxx) == true) {
                $('#imgLoadingabc').show();
                var options = {
                    type: 'POST',
                    url: 'WebService1.asmx/setReject',
                    data: '{sn: "' + sn + '", _curUser: "' + curUser + '"}',
                    contentType: 'application/json; charset=utf-8',
                    dataType: 'json',
                    success: function (msg) {
                        if (msg.d == "DONE") {//OK
                            $("#span" + sn).text(msg.d);
                            $("#span" + sn).css({ "color": "red", "opacity": ".50" });
                            $('#btn' + sn).attr("disabled", true);
                            $('#btn' + sn).attr("value", "Rejected");
                        }
                        if (msg.d == "FAIL") {//have sql Error, 
                            $("#span" + sn).text(msg.d);
                            $("#span" + sn).css({ "color": "red", "opacity": ".50" });
                            $('#btn' + sn).attr("disabled", false);
                            $('#btn' + sn).attr("value", "Reject");
                        }
                        $('#imgLoadingabc').hide();
                    },
                    error: function (msg) {
                        $('#imgLoadingabc').hide();
                        alert("Unknow Error: " + msg.d)
                    }
                };
                $.ajax(options);
            }
        }

        function findToConfirm(rowTotal, curRow, p_serial_no, p_box_no, p_model, p_suffix, p_prod_date, p_act_user) {
            var bill = $('#txtBill').val();
            if (bill == '') {
                alert("You must input Bill No");
                return;
            }

            var modelIsUnlock = document.getElementById('modelIsUnlock');
            var txtModel = document.getElementById('txtModel');
            var md = txtModel.value;
            if (modelIsUnlock.value != '1') {
                txtModel.value = p_model;
            }

            var suffixIsUnlock = document.getElementById('suffixIsUnlock');
            var txtSuffix = document.getElementById('txtSuffix');
            var sf = txtSuffix.value;
            if (suffixIsUnlock.value != '1') {
                txtSuffix.value = p_suffix;
            }

            for (var i = 1; i <= rowTotal; i++) {
                $("#tr" + i).css({ "color": "black", "opacity": ".50" });
            }
            $("#tr" + curRow).css({ "color": "red", "opacity": ".50" });

            findPickOrder(bill, txtModel.value, txtSuffix.value, p_serial_no, p_box_no, p_prod_date, p_act_user);
        }
        function findPickOrder(p_billto_code, p_model, p_suffix, p_serial_no, p_box_no, p_prod_date, p_act_user) {
            $('#imgLoadingabc').show();
            var options = {
                type: 'POST',
                url: 'WebService1.asmx/findPickOrder',
                data: '{p_billto_code: "' + p_billto_code + '", p_model: "'
                + p_model + '", p_suffix: "' + p_suffix + '", p_serial_no: "' + p_serial_no
                + '", p_box_no: "' + p_box_no + '", p_prod_date: "' + p_prod_date + '", p_act_user: "' + p_act_user + '"}',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (msg) {
                    $("#tblOrder").html(msg.d);
                    $('#imgLoadingabc').hide();
                    FormatTable();
                },
                error: function (msg) {
                    $('#imgLoadingabc').hide();
                    alert("Unknow Error: " + msg.d)
                }
            };
            $.ajax(options);
        }
        function findToConfirm2(rowTotal, curRow, p_serial_no, p_act_user) {
            //khi ko tim thay data, van chay Confirm
            //input by hand: model+suffix+bill+prod_date
            var bill = $('#txtBill').val();
            if (bill == '') {
                alert("You must input Bill No");
                return;
            }

            var modelIsUnlock = document.getElementById('modelIsUnlock');
            var txtModel = document.getElementById('txtModel');
            var md = txtModel.value;
            if (modelIsUnlock.value != '1') {
                txtModel.value = p_model;
            }

            var suffixIsUnlock = document.getElementById('suffixIsUnlock');
            var txtSuffix = document.getElementById('txtSuffix');
            var sf = txtSuffix.value;
            if (suffixIsUnlock.value != '1') {
                p_suffix = sf;
            }

            for (var i = 1; i <= rowTotal; i++) {
                $("#tr" + i).css({ "color": "black", "opacity": ".50" });
            }
            $("#tr" + curRow).css({ "color": "red", "opacity": ".50" });

            $('#divProDatePopup').modal({ containerCss: {
                height: 100,
                width: 500
            }
            });
            $("#txtProDate").attr('readOnly', 'true');
            $("#txtProDate").datepicker({ dateFormat: 'yy-mm-dd' });
            $("#btnFindPickOrder").attr("onclick", "confirmProdDate('" + bill + "," + txtModel.value + "," + p_suffix + "," + p_serial_no + "," + p_serial_no + "," + p_act_user + "')");

        }
        function confirmProdDate(st) {
            var d = $('#txtProDate').val();
            if (d == "") {
                alert("You must input Produce Date.");
                return;
            }
            else {
                var lines2 = st.split(',');
                var p_billto_code = '';
                var p_model = '';
                var p_suffix = '';
                var p_serial_no = '';
                var p_box_p_modelno = '';
                var p_act_user = '';
                var p_prod_date = d;
                $.each(lines2, function (key, line) {
                    p_billto_code = lines2[0];
                    p_model = lines2[1];
                    p_suffix = lines2[2];
                    p_serial_no = lines2[3];
                    p_box_p_modelno = lines2[4];
                    p_act_user = lines2[5];
                });
                $.modal.close();
                findPickOrder2(p_billto_code, p_model, p_suffix, p_serial_no, p_serial_no, p_act_user, p_prod_date);
            }
        }
        function findPickOrder2(p_billto_code, p_model, p_suffix, p_serial_no, p_box_no, p_act_user, p_prod_date) {
            $('#imgLoadingabc').show();
            var options = {
                type: 'POST',
                url: 'WebService1.asmx/findPickOrder',
                data: '{p_billto_code: "' + p_billto_code + '", p_model: "'
                + p_model + '", p_suffix: "' + p_suffix + '", p_serial_no: "' + p_serial_no
                + '", p_box_no: "' + p_box_no + '", p_prod_date: "' + p_prod_date + '", p_act_user: "' + p_act_user + '"}',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (msg) {
                    $("#tblOrder").html(msg.d);
                    $('#imgLoadingabc').hide();
                    FormatTable();
                },
                error: function (msg) {
                    $('#imgLoadingabc').hide();
                    alert("Unknow Error: " + msg.d)
                }
            };
            $.ajax(options);
        }
        function doConfirm(p_billto_code, p_pick_no, p_serial_no, p_box_no, p_model, p_suffix, p_prod_date, p_act_user) {
            var xxx = ("p_pick_no: " + p_pick_no + "\n"
                + "p_serial_no: " + p_serial_no + "\n"
                + "p_box_no: " + p_box_no + "\n"
                + "p_model: " + p_model + "\n"
                + "p_suffix: " + p_suffix + "\n"
                + "p_prod_date: " + p_prod_date + "\n"
                + "p_act_user: " + p_act_user + "\n"
                + "\n\n Are you sure confirm this data...?");

            if (confirm(xxx) == true) {
                $('#imgLoadingabc').show();
                var suffixIsUnlock = document.getElementById('suffixIsUnlock');
                var txtSuffix = document.getElementById('txtSuffix');
                var sf = txtSuffix.value;
                if (suffixIsUnlock.value != '1') {
                    txtSuffix.value = p_suffix;
                }
                var options = {
                    type: 'POST',
                    url: 'WebService1.asmx/doConfirm',
                    data: '{p_pick_no: "' + p_pick_no + '", p_serial_no: "' + p_serial_no + '", p_box_no: "' + p_box_no + '", p_model: "' + p_model + '", p_suffix: "' + p_suffix + '", p_prod_date: "' + p_prod_date + '", p_act_user: "' + p_act_user + '"}',
                    contentType: 'application/json; charset=utf-8',
                    dataType: 'json',
                    success: function (msg) {
                        alert(msg.d);
                        $('#imgLoadingabc').hide();
                    },
                    error: function (msg) {
                        $('#imgLoadingabc').hide();
                        alert("Unknow Error: " + msg.d)
                    }
                };
                $.ajax(options);
            }
        }

        function setUnlockModel() {
            $("#txtModel").removeAttr("disabled");
            $("#txtModel").removeAttr("class");
            var modelIsUnlock = document.getElementById('modelIsUnlock');
            modelIsUnlock.value = '1';
            document.getElementById("imgModelUnlock").src = "../IMAGES/Unlock-icon.png";
        }
        function setUnlockSuffix() {
            $("#txtSuffix").removeAttr("disabled");
            $("#txtSuffix").removeAttr("class");
            var suffixIsUnlock = document.getElementById('suffixIsUnlock');
            suffixIsUnlock.value = '1';
            document.getElementById("imgSuffixUnlock").src = "../IMAGES/Unlock-icon.png";
        }
        function openPopUp(popUrl, type) {
            var name = 'popUp';
            var appearence = 'dependent=no,menubar=no,resizable=yes,scrollbars=1,' +
                  'status=yes,toolbar=yes,titlebar=yes,' +
                  'width=' + window.screen.availWidth * 90 / 100 + ', height=' + window.screen.availHeight * 100 / 100 + ',resizable:yes,center:yes';
            var openWindow = '';
            if (type == 'open')
                openWindow = window.open(popUrl, name, appearence);
            if (type == 'popup')
                openWindow = window.showModalDialog(popUrl, name, appearence);
            openWindow.focus();
        }
        function ShowPopupfindModel() {
            var m = $('#txtModel').val();
            var txtModelPopup = document.getElementById('txtModelPopup');
            txtModelPopup.value = m;

            $('#divFindModel').modal();
            if (m.length > 2) {
                findModel();
            }
        }
        function findModel() {
            var md = $('#txtModelPopup').val();
            if (md.length <= 2) {
                alert("You must input at least 3 character of Model");
                return;
            }
            $('#imageLoadingPopup').show();
            var options = {
                type: 'POST',
                url: 'WebService1.asmx/findModel',
                data: '{md: "' + md + '"}',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (msg) {
                    $("#divModelPopup").html(msg.d);
                    $('#imageLoadingPopup').hide();
                    FormatTable();
                },
                error: function (msg) {
                    $('#imageLoadingPopup').hide();
                    alert("Unknow Error: " + msg.d)
                }
            };
            $.ajax(options);
        }

        function setSelectOnPopup(rowTotal, curRow, PROD_MODEL_SUFFIX, SALES_MODEL, SALES_SUFFIX) {
            //md=model.suffix
            for (var i = 1; i <= rowTotal; i++) {
                $("#btnSelect" + i).show();
                $("#imgSelect" + i).hide();
            }
            $("#btnSelect" + curRow).hide()
            $("#imgSelect" + curRow).show();

            var lines2 = (PROD_MODEL_SUFFIX).split('.');
            var Pm = '';
            var Ps = '';
            $.each(lines2, function (key, line) {
                Pm = lines2[0];
                Ps = lines2[1];
            });
            var txtModel = document.getElementById('txtModel');
            var txtSuffix = document.getElementById('txtSuffix');
            if (SALES_MODEL != '' && SALES_MODEL != 'undefined')
                txtModel.value = SALES_MODEL;
            else
                txtModel.value = Pm;
            if (SALES_SUFFIX != '' && SALES_SUFFIX != 'undefined')
                txtSuffix.value = SALES_SUFFIX;
            else
                txtSuffix.value = Ps;

            //set unlock
            setUnlockModel();
            setUnlockSuffix();

            $.modal.close();


        }
        function setSelectOnPopup2(rowTotal, curRow, bill) {
            for (var i = 1; i <= rowTotal; i++) {
                $("#btnSelect" + i).show();
                $("#imgSelect" + i).hide();
            }
            $("#btnSelect" + curRow).hide()
            $("#imgSelect" + curRow).show();

            var txtBill = document.getElementById('txtBill');
            txtBill.value = bill;

            $.modal.close();

        }

        function ShowPopupfindBill() {
            var b = $('#txtBill').val();
            var txtBillPopup = document.getElementById('txtBillPopup');
            txtBillPopup.value = b;

            $('#divFindBill').modal();
            if (b.length > 2) {
                findBill();
            }
        }
        function findBill() {
            var bill = $('#txtBillPopup').val();
            if (bill.length <= 2) {
                alert("You must input at least 3 character of BILL");
                return;
            }
            $('#imageLoadingPopup2').show();
            var options = {
                type: 'POST',
                url: 'WebService1.asmx/findBill',
                data: '{bill: "' + bill + '"}',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (msg) {
                    $("#divBillPopup").html(msg.d);
                    $('#imageLoadingPopup2').hide();
                    FormatTable();
                },
                error: function (msg) {
                    $('#imageLoadingPopup2').hide();
                    alert("Unknow Error: " + msg.d)
                }
            };
            $.ajax(options);
        }
        $(document).ready(function () {
            $("#txtModelPopup").keypress(function (event) {
                if (event.which == 13) {
                    event.preventDefault();
                    findModel();
                }
            });

            $("#txtBillPopup").keypress(function (event) {
                if (event.which == 13) {
                    event.preventDefault();
                    findBill();
                }
            });
        });


    </script>
    <style>
        .dataTables_filter
        {
            float: left;
            padding-bottom: 10px;
        }
        .bigdrop.select2-container .select2-results
        {
            max-height: 300px;
        }
        .bigdrop .select2-results
        {
            max-height: 300px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ksdjfl" runat="server">
    </asp:ScriptManager>
    <div class="TitleCont">
        Serial confirmation
    </div>
    <div class="Mid2">
        <div class="Search2">
            <table id="newspaper-b">
                <tbody>
                    <tr>
                        <%--<td class="BackGround-gray">
                            Serial No<span style="color: Red;">*</span>
                        </td>
                        <td>
                            <asp:TextBox ID="txtSN" ClientIDMode="Static" runat="server" Width="100px" Enabled="false"></asp:TextBox>
                        </td>--%>
                        <td class="BackGround-gray">
                            Model
                        </td>
                        <td>
                            <asp:TextBox ID="txtModel" ClientIDMode="Static" Enabled="false" runat="server"></asp:TextBox>
                            <img id='imgModelUnlock' src="../IMAGES/Lock-icon.png" onclick="setUnlockModel()"
                                title="Unlock" />
                            <img id='img1' src="../IMAGES/Search-icon.png" onclick="ShowPopupfindModel()" title="Find Model"
                                style="cursor: pointer;" />
                            <input type="hidden" id="modelIsUnlock" value="0" />
                        </td>
                        <td class="BackGround-gray">
                            Suffix
                        </td>
                        <td>
                            <asp:TextBox ID="txtSuffix" ClientIDMode="Static" Enabled="false" runat="server"></asp:TextBox>
                            <img id='imgSuffixUnlock' src="../IMAGES/Lock-icon.png" onclick="setUnlockSuffix()"
                                title="Unlock" />
                            <input type="hidden" id="suffixIsUnlock" value="0" />
                        </td>
                        <td class="BackGround-gray">
                            BIll Code
                        </td>
                        <td>
                            <asp:TextBox ID="txtBill" runat="server"></asp:TextBox>
                            <img id='img2' src="../IMAGES/Search-icon.png" onclick="ShowPopupfindBill()" title="Find Bill"
                                style="cursor: pointer;" />
                        </td>
                        <td>
                            <input type='button' value="Close" style="width: 80px;" class="button Float-right"
                                onclick="javascript:window.close();" />
                        </td>
                    </tr>
                    <%--<tr>
                        <td colspan="2">
                            <asp:Button ID="btnFind" runat="server" Enabled="false" Width="80px" CssClass="button Float-right"
                                Text="Serial" OnClick="btnFind_Click" />
                        </td>
                        <td colspan="6">
                            <asp:Button ID="btnOrder" runat="server" Width="80px" CssClass="button Float-right"
                                Visible="false" Text="Order" OnClick="btnOrder_Click" />
                        </td>
                    </tr>--%>
                </tbody>
            </table>
            <div style='padding-bottom: 10px;'>
            </div>
            <div id="divData" runat="server">
                <div style="width: 100%; overflow: auto; height: 200px;">
                    <table id="newspaper-b">
                        <thead>
                            <tr>
                                <th scope="col">
                                    #
                                </th>
                                <th scope="col">
                                    <nobr>  SERIAL_NO</nobr>
                                </th>
                                <th scope="col">
                                    <nobr>  BOX_NO</nobr>
                                </th>
                                <th scope="col">
                                    <nobr>   PROD_MODEL</nobr>
                                </th>
                                <th scope="col">
                                    <nobr>  PROD_SUFFIX</nobr>
                                </th>
                                <th scope="col">
                                    <nobr>    SAL_MODEL</nobr>
                                </th>
                                <th scope="col">
                                    <nobr>    SAL_SUFFIX</nobr>
                                </th>
                                <th scope="col">
                                    <nobr> ORDER NO</nobr>
                                </th>
                                <th scope="col">
                                    <nobr>  PRODUCT DATE</nobr>
                                </th>
                                <th scope="col">
                                    <nobr>    SELLIN DATE</nobr>
                                </th>
                                <th scope="col">
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <asp:Literal ID='litData' runat='server'></asp:Literal>
                        </tbody>
                    </table>
                </div>
                <div style='padding-bottom: 10px; text-align: center; display: none' id="imgLoadingabc">
                    <img src="../IMAGES/red_loading.gif" />
                </div>
                <div style='padding-bottom: 10px;'>
                </div>
            </div>
            <div id="divData2" runat="server" visible="false">
                <table id="newspaper-b">
                    <thead>
                        <tr>
                            <th scope="col">
                                REJECT STATUS
                            </th>
                            <th scope="col">
                                SHOP CODE
                            </th>
                            <th scope="col">
                                PRODUCT
                            </th>
                            <th scope="col">
                                MODEL
                            </th>
                            <th scope="col">
                                SERIAL NO
                            </th>
                            <th scope="col">
                                SHOP CELL
                            </th>
                            <th scope="col">
                                ENDUSER CELL
                            </th>
                            <th scope="col">
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <asp:Literal ID='litData2' runat='server'></asp:Literal>
                    </tbody>
                </table>
            </div>
            <div style='padding-bottom: 10px;'>
            </div>
            <div id="tblOrder" style="width: 100%; overflow: auto;">
            </div>
            <div style='padding-bottom: 10px;'>
            </div>
            <div id="divFindModel" runat="server" style="display: none;">
                <table id="newspaper-b">
                    <tbody>
                        <tr>
                            <td>
                                Model:
                            </td>
                            <td>
                                <input type="text" id="txtModelPopup" />
                            </td>
                            <td>
                                <input type='button' id="btnFindModelPopup" onclick="findModel()" value="Search"
                                    style="width: 80px;" class="button" />
                            </td>
                        </tr>
                    </tbody>
                </table>
                <div style='padding-bottom: 10px; text-align: center; display: none' id="imageLoadingPopup">
                    <img src="../IMAGES/red_loading.gif" />
                </div>
                <div style='padding-bottom: 20px; text-align: center;'>
                </div>
                <div id="divModelPopup" style="width: 100%; overflow: auto;">
                </div>
            </div>
            <div id="divFindBill" runat="server" style="display: none;">
                <table id="newspaper-b">
                    <tbody>
                        <tr>
                            <td>
                                Bill Name:
                            </td>
                            <td>
                                <input type="text" id="txtBillPopup" />
                            </td>
                            <td>
                                <input type='button' id="btnFindBillPopup" onclick="findBill()" value="Search" style="width: 80px;"
                                    class="button" />
                            </td>
                        </tr>
                    </tbody>
                </table>
                <div style='padding-bottom: 10px; text-align: center; display: none' id="imageLoadingPopup2">
                    <img src="../IMAGES/red_loading.gif" />
                </div>
                <div style='padding-bottom: 20px; text-align: center;'>
                </div>
                <div id="divBillPopup" style="width: 100%; overflow: auto;">
                </div>
            </div>
            <div id="divProDatePopup" style="display: none;">
                <table id="newspaper-b">
                    <tbody>
                        <tr>
                            <td>
                                Produce Date:
                                <input type='hidden' id="hiddenProDatePopupPara" />
                            </td>
                            <td>
                                <input type="text" id="txtProDate" />
                            </td>
                            <td>
                                <input type='button' id="btnFindPickOrder" value="Search" style="width: 80px;" class="button" />
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="Clear_both">
        </div>
    </div>
    </form>
</body>
</html>
